package borge.web.teamspirit.client.panels;

import borge.web.teamspirit.client.interfaces.MenuEventHandler;
import borge.web.teamspirit.client.interfaces.PanelHandler;
import borge.web.teamspirit.client.interfaces.WidgetEventHandler;
import borge.web.teamspirit.client.widgets.ListEventsWidget;
import borge.web.teamspirit.client.widgets.MenuWidget;

import com.google.gwt.user.client.ui.VerticalPanel;

public class LeftPanel extends VerticalPanel implements WidgetEventHandler {
	
	private MenuWidget iMenuWidget;
	private MenuEventHandler iMenuEventHandler;
	private ListEventsWidget iListEventsWidget;
	private PanelHandler iPanelHandler;
	
	public LeftPanel(MenuEventHandler aEventHandler, PanelHandler aPanelHandler){
		
	    iMenuEventHandler = aEventHandler;
	    iPanelHandler = aPanelHandler;
		iMenuWidget = new MenuWidget(this);
		iListEventsWidget = new ListEventsWidget(this, null);
		
		add(iMenuWidget);
		add(iListEventsWidget);
	}
	
	public void handleWidgetEvent(WidgetEventType aEvent){
		
	    switch(aEvent){
	    
	    case MENU_CLICKED: {
	        
	        iMenuEventHandler.handleMenuEvent(iMenuWidget.getClickedLinkText());
	        break;
	    }
	    case CLEAR_MENU: {
	        iMenuWidget.clearClickHistory();
	        break;
	    } 
	    
	    case SHOW_EVENT: {
	    	iPanelHandler.switchPanel(aEvent, iListEventsWidget);
	    	break;
	    }
	    
	    }
	    
	}

}
